/**
 * Copyright (c) iwindplus Technologies Co., Ltd.2024-2030, All rights reserved.
 */

package com.iwindplus.auth.domain.enums;

import com.iwindplus.base.domain.exception.CommonException;
import java.util.Arrays;
import java.util.Objects;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

/**
 * 业务编码枚举.
 *
 * @author zengdegui
 * @since 2020/6/13
 */
@Getter
@RequiredArgsConstructor
public enum AuthCodeEnum implements CommonException {
    /**
     * 用户登录异常.
     */
    USER_LOGIN_ABNORMAL(900210, "user_login_abnormal", "用户登录异常"),

    /**
     * 授权类型不能为空.
     */
    GRANT_TYPE_EMPTY(900230, "grant_type_empty", "授权类型不能为空"),

    /**
     * 用户授权申请被拒绝.
     */
    AUTHORIZATION_DENIED(900231, "authorization_denied", "用户授权申请被拒绝"),

    /**
     * 不支持的授权类型.
     */
    UNSUPPORTED_GRANT_TYPE(900232, "unsupported_grant_type", "不支持的授权类型"),

    /**
     * 未授权的客户端.
     */
    UNAUTHORIZED_CLIENT(900233, "unauthorized_client", "未授权的客户端"),

    /**
     * 无效的客户端.
     */
    INVALID_CLIENT(900234, "invalid_client", "无效的客户端"),

    /**
     * 客户端不存在.
     */
    CLIENT_NOT_EXIST(900235, "client_not_exist", "客户端不存在"),

    /**
     * 客户端密码不能为空.
     */
    CLIENT_PASSWORD_EMPTY(900236, "client_password_empty", "客户端密码不能为空"),

    /**
     * 客户端密码错误.
     */
    CLIENT_PASSWORD_ERROR(900237, "client_password_error", "客户端密码错误"),

    /**
     * 客户端密钥已过期.
     */
    CLIENT_SECRET_EXPIRED(900238, "client_secret_expired", "客户端密钥已过期"),

    /**
     * 无效的请求.
     */
    INVALID_REQUEST(900239, "invalid_request", "无效的请求"),

    /**
     * 无效的授权.
     */
    INVALID_GRANT(900240, "invalid_grant", "无效的授权"),

    /**
     * 无效的scope.
     */
    INVALID_SCOPE(900241, "invalid_scope", "无效的scope"),

    /**
     * 客户端禁用.
     */
    CLIENT_DISABLE(900242, "client_disable", "客户端禁用"),

    /**
     * 用户身份校验失败.
     */
    IDENTITY_VERIFICATION_FAILED(900243, "identity_verification_failed", "用户身份校验失败");

    /**
     * 业务状态码.
     */
    private final Integer bizStatus;

    /**
     * 业务编码.
     */
    private final String bizCode;

    /**
     * 业务信息.
     */
    private final String bizMessage;

    /**
     * 通过业务状态码查找枚举.
     *
     * @param bizStatus 业务状态码
     * @return AuthCodeEnum
     */
    public static AuthCodeEnum valueOfBizStatus(Integer bizStatus) {
        return Arrays.stream(AuthCodeEnum.values())
            .filter(m -> Objects.equals(bizStatus, m.getBizStatus())).findFirst().orElse(null);
    }
}
